package com.forg.dubbox.example.consumer.controller;

import com.forg.dubbox.example.consumer.service.NormalConsumerServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by forgkan on 15.11.10.
 */
@Controller
public class IndexContrller {

    @Autowired
    NormalConsumerServiceImpl normalConsumerService;
    private static final Logger logger = LoggerFactory.getLogger(IndexContrller.class);


    @RequestMapping("/index")
    public String index(){

        return "index";
    }

    @RequestMapping({"/str"})
    public String invokeGetStr(Integer times, Integer size, ModelMap m)
    {
        if ((times == null) || (times.intValue() <= 0)) {
            times = Integer.valueOf(1);
        }
        if ((size == null) || (size.intValue() <= 0)) {
            size = Integer.valueOf(1);
        }
        logger.info("page invokeGetStr times {}, size {}", times, size);
        m.addAttribute("result", this.normalConsumerService.getStr(times.intValue(), size.intValue()));

        return "str";
    }

    @RequestMapping({"/sayHello"})
    @ResponseBody
    public String sayHello(String name)
    {
        if (StringUtils.isEmpty(name)) {
            name = "anonymous";
        }
        return this.normalConsumerService.sayHello(name);
    }



}
